package com.zhangxin.designmode.fiveprinciple.liskovsubstitutionprinciple.before;

import org.springframework.util.StringUtils;
import sun.net.www.http.HttpClient;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author zhangxin
 * @date 2022/4/9
 */
public class SecurityTransporter extends Transporter {

    private String appId;
    private String appToken;

    public SecurityTransporter(HttpClient httpClient, String appId, String appToken) {
        super(httpClient);
        this.appId = appId;
        this.appToken = appToken;
    }

    @Override
    public HttpServletResponse sendRequest(HttpServletRequest request) {
        if (StringUtils.hasLength(appId) && StringUtils.hasLength(appToken)) {
            request.setAttribute("app-id", appId);
            request.setAttribute("app-token", appToken);
        }
        return super.sendRequest(request);
    }
}
